package context

import (
	"log"

	"gitee.com/dayu1985/framework/logging"
)

const SECTION_LOGGER = "logging"

func initLogger(conf *Configuration) {

	fileName := conf.INI.MustValue(SECTION_LOGGER, "filename", "./app.log")
	maxSize := conf.INI.MustInt(SECTION_LOGGER, "max-size", 128)
	maxBackups := conf.INI.MustInt(SECTION_LOGGER, "max-backups", 3)
	maxAge := conf.INI.MustInt(SECTION_LOGGER, "max-age", 28)
	gzip := conf.INI.MustBool(SECTION_LOGGER, "gzip", true)
	logging.Level = conf.INI.MustInt(SECTION_LOGGER, "level", 2)

	log.SetOutput(&logging.Logger{

		Filename:   fileName,
		Gzip:       gzip,
		MaxSize:    maxSize, // megabytes
		MaxBackups: maxBackups,
		MaxAge:     maxAge, //days
	})
}
